﻿using Framework.Core;
using Xunit;

namespace Framework.Tests.Core
{

    // ReSharper disable UnusedTypeParameter
    internal class GenericTypeClass<T>
    {
    }

    internal class TypeClass : GenericTypeClass<string>
    {
    }

    internal interface IGenericInterface<T>
    {
    }

    internal class ImplementedClass : IGenericInterface<string>
    {
    }

    internal interface IDerivedInterface : IGenericInterface<string>
    {
    }

    internal interface IImplementedGeneric : IGenericInterface<GenericTypeClass<string>>
    {
    }

    // ReSharper restore UnusedTypeParameter

    public class TypeExtensionIsAssignableFromGenericTest
    {
        [Fact]
        public void Type_derived_generic_class_is_assignable_from_generic()
        {
            Assert.True(typeof (GenericTypeClass<>).IsAssignableFromGenericType(typeof (TypeClass)));
        }

        [Fact]
        public void Type_parameter_is_not_assignable_from_generic()
        {
            Assert.False(typeof (string).IsAssignableFromGenericType(typeof (TypeClass)));
        }

        [Fact]
        public void Type_Implements_Generic_Interface_is_assignable_from_his_generic_interface()
        {
            Assert.True(typeof (IGenericInterface<>).IsAssignableFromGenericType(typeof (ImplementedClass)));
        }

        [Fact]
        public void Interface_derives_Generic_Interface_is_assignable_from_his_generic_interface()
        {
            Assert.True(typeof (IGenericInterface<>).IsAssignableFromGenericType(typeof (IDerivedInterface)));
        }

        [Fact]
        public void Interface_derives_Generic_Interface_with_generic_parameter_is_assignable_from_his_generic_interface()
        {
            Assert.True(typeof (IGenericInterface<>).IsAssignableFromGenericType(typeof (IDerivedInterface)));
        }
    }
}